<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title><?= $page_title ?></title>
    <?php include(APPLICATION_BASE_TPL_PATH . "/inc/include.phtml"); ?>
    <!--include-wechat-start-->
</head>
<body>
<div id="wrapper">
    <?php echo $menuview; ?>
    <div id="page-wrapper" style="min-height: 0;padding-top: 15px;">
        <div class="row">
            <a class="btn btn-primary btn-right btn-lg" onclick="javascript:openDialog(url('/product/edit'));">新增商品</a>
        </div>
        <div class="row">
            <div class="panel panel-condensed panel-default panel-hover">
                <div class="panel-heading">
                    <h5 class="panel-title"><span class="glyphicon glyphicon-list"></span> 商品列表</h5>
                </div>

                <?php if (empty($list)): ?>
                    <div class="panel-body">无资料</div>
                <?php else: ?>

                    <table class="table table-bordered table-responsive table-condensed table-hover">
                        <thead>
                        <tr>
                            <th>商品id</th>
                            <th>价格（元）</th>
                            <th>时长（分钟）</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>
                        <?php foreach ($list as $item): ?>
                            <tr>
                                <td data-id="<?= $item['pid'] ?>"><?= $item['pid'] ?></td>
                                <td style="text-align: center;"><?= $item['price'] ?></td>
                                <td style="text-align: center;"><?= $item['minute'] ?></td>
                                <td style="text-align: center;">
                                    <a onclick="javascript:openDialog(url('/product/edit?pid=<?= $item['pid'] ?>'));" class="btn btn-primary">编辑</a>
                                    <a href="javascript:void(0);" class="btn btn-danger del-product" pid="<?= $item['pid'] ?>">删除</a>
                                </td>
                            </tr>
                        <?php endforeach; ?>
                        </tbody>
                    </table>

                <?php endif; ?>
            </div>
        </div>


        <div class="row" style="display: none;">
            <pre><?php #var_export($type_list); ?></pre>
            <pre><?php #var_export($list); ?></pre>
            <pre><?php #var_export($oa_list); ?></pre>

        </div>
        <!-- /#page-wrapper -->

    </div>
    <!-- /#wrapper -->

</body>
<script type="text/javascript">
    $('.del-product').on('click',function(){
        var pid = $(this).attr('pid');
        if(confirm("确认删除编号为 "+pid+" 的商品?")){
            $.post("<?=APP_ADMIN_PATH?>/product/delete",{pid : pid},function(result){
                if(result.retcode == 2000000){
                    alert(result.msg);
                    refresh();
                }else{
                    alert('发生错误，保存失败:'+result.retcode);
                }

            });
        }
    });
</script>
</html>
